package controllers.zen;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import controllers.SuperServlet;

import applicationModels.Juego;
import appmodel.ZenAppModel;

import dominio.JardinZen;

@SuppressWarnings("serial")
public class JardinZenServlet extends SuperServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		makeGameInstance(request);
		this.makeJardinZen(request);

		// Guardo el estado que quiero comunicar a la vista
		ZenAppModel app = getJardinZen(request);
		request.setAttribute("plantas", app.getJardinZen());
		
		// Delego a la vista
		request.getRequestDispatcher("jardinzen.jsp").forward(request, response);
	}
	
	public void makeJardinZen(HttpServletRequest request) {
		if ((request.getSession().getAttribute("jardinZen")) == null) {
			JardinZen zen = ((Juego) request.getSession().getAttribute("juego")).getUsuario().getJardinZen();
			ZenAppModel appModel = new ZenAppModel(zen);
			
			request.getSession().setAttribute("jardinZen", appModel);
		}
	}
}
